package com.burgeon.backend.EnterpriseWeChat.controller;

import com.burgeon.backend.EnterpriseWeChat.service.EWBackendService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

@RestController
@CrossOrigin
@RequestMapping("ew/backend")
public class EWBackendController extends EWBaseController {

    @Autowired
    private EWBackendService ewBackendService;


    @RequestMapping("addEmp")
    public ResponseResult<Void> addEmp(String id,String account){
        String[] ids = new String[]{id};
        ewBackendService.MassProductionEWEmp(account,ids);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("addEmpAll")
    public ResponseResult<Void> addEmpAll(String account){
        ewBackendService.MassProductionEWEmpAll(account);
        return new ResponseResult<>(SUCCESS);
    }


    @RequestMapping("incident/{token}")
    public void getRecord(HttpServletRequest req, ServletResponse res, @PathVariable("token") String token) {
        System.err.println(token);
        //http://lfwd.cloudsmicro.com/ew/backend/incident/lfwd
        String CORP_ID = "wwbc29d2d2ca450d92"; //CorpId, 企业号的普通管理组中可查看eWechat.getCorpid()
        /*String SUITE_ID = "tja2312bedd5086xxx";    //套件ID，在套件信息中查看
        String SUITE_SECRET = "LGVT0BrN2DZ7VMTuIPOsudaWuXOE0iM67yHpIs1ofESS4l-jSC8LN9nOnmilhXXX";*/
        String SUITE_TOKEN = "uAuSzcE5lS78o3a9L";//eWechat.getSuiteToken()
        String SUITE_ENCODING_AES_KEY = "q9wY8sCjL4MqCwj8mbnsexacLtp32f2JmdrygIo8lMy";//eWechat.getEncodingAESKey()

        //获取参数
        String msgSignature = req.getParameter("msg_signature");
        String timestamp = req.getParameter("timestamp");
        String nonce = req.getParameter("nonce");
        String echostr = req.getParameter("echostr");    //创建套件时验证回调url时传入


        ewBackendService.WXSaaSCallback(req, res, CORP_ID, SUITE_TOKEN, SUITE_ENCODING_AES_KEY,
                msgSignature, timestamp, nonce, echostr,token);

    }
}